package com.gurun.model.database;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.content.Context;

import com.gurun.model.database.dao.GateWayDao;
import com.gurun.model.database.entity.GateWayCommand;

@Database(
        entities = {
                GateWayCommand.class
        },
        version = 1,
        exportSchema = false
)
public abstract class AppDatabase extends RoomDatabase {

    private static volatile AppDatabase INSTANCE;

    public abstract GateWayDao GateWayDao();

    public static AppDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            synchronized (AppDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(
                            context.getApplicationContext(), AppDatabase.class, "stbandgateway-app.db")
                            .build();
                }
            }
        }
        return INSTANCE;
    }
}

